Skip to content

Add support for bitcoin core 29.0 #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GideonBature
Copy link
Contributor

@GideonBature GideonBature commented Apr 19, 2025

This PR adds support for the newly released bitcoin core version - v29.0

Updated RPCs

  • Implement getmininginfo which now returns nBits and the current target in the target field. It also returns a next object which specifies the height, nBits, difficulty, and target for the next block. (test added)
  • Implement getblock and getblockheader which now return the current target in the target field (test added)
  • Implement getblockchaininfo and getchainstates which now return nBits and the current target in the target field. (test added)
  • Implement getblocktemplate whose RPC curtime (BIP22) and mintime (BIP23) fields now account for the timewarp fix proposed in BIP94 on all networks. (test added)

New RPCs

  • Implement getdescriptoractivity rpc method which can be used to find all spend/receive activity relevant to a given set of descriptors within a set of specified blocks. (test added)

Closes #129

@GideonBature GideonBature force-pushed the support-29.0 branch 4 times, most recently from 5438355 to 1dbf4df Compare April 19, 2025 18:15
@tcharding
Copy link
Member

CI fail can be fixed by creating the RPC help file, I haven't downloaded Core v29 yet but I'd expect that on this branch we could do:

contrib/run-bitcoind.sh start v29
bt29 help > verify/rpc-api-v29.txt

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man this is looking pretty good! This crate is hard to work on so don't feel bad if you miss things. I'm having a hard time reviewing because the changeset is so big but I've left a few comments that will make it a fair bit smaller. Keep at it! Appreciate your effort.

@GideonBature
Copy link
Contributor Author

CI fail can be fixed by creating the RPC help file, I haven't downloaded Core v29 yet but I'd expect that on this branch we could do:

contrib/run-bitcoind.sh start v29
bt29 help > verify/rpc-api-v29.txt

I tried running the command after starting the bitcoind v29, but it keeps say the bt29 command not found, checked the repository to see if I can get anything that relates to that, but didn't find any...

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from dc856f3 to 3c6c22f Compare April 22, 2025 20:08
@tcharding
Copy link
Member

Oh I have a shell alias for each version, for v28 I have

bt28: aliased to bitcoin-cli -rpcconnect=localhost:28049 -rpcuser=*** -rpcpassword=***

And fill in the stars for your setup. Remember the leading 280 comes from the config file of .run-bitcoind.conf

@GideonBature
Copy link
Contributor Author

Oh I have a shell alias for each version, for v28 I have

bt28: aliased to bitcoin-cli -rpcconnect=localhost:28049 -rpcuser=*** -rpcpassword=***

And fill in the stars for your setup. Remember the leading 280 comes from the config file of .run-bitcoind.conf

Thank you... It's done!

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 798a62e to 2308f10 Compare April 23, 2025 05:19
@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 20080f5 to 87a78dd Compare April 28, 2025 15:15
@tcharding
Copy link
Member

Can you get rid of all the formatting changes please.

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from fb921bd to 5709498 Compare April 29, 2025 16:46
@GideonBature
Copy link
Contributor Author

Can you get rid of all the formatting changes please.

Done!

@GideonBature GideonBature force-pushed the support-29.0 branch 3 times, most recently from fa9350a to 1db66bf Compare April 29, 2025 17:13
@tcharding
Copy link
Member

It is surprising to see changes to types modules for any version other than v29. There are changes to v17. Please either remove them or justify why the changes are made.

@GideonBature
Copy link
Contributor Author

It is surprising to see changes to types modules for any version other than v29. There are changes to v17. Please either remove them or justify why the changes are made.

Alright, so for v29, the getblocktemplate returns a Target field, in that case, I saw that v17 already has the getblocktemplate error, thus, I decided to add the target field Error variant to it so I could just reuse it for v29 instead of implementing the same thing for v29... I don't know if that counts... That was the reason why I added the additional field, but if it doesn't align with how the codebase is supposed to be, I can revert it back to it's original form and re-implement the error for v29 with target field....

@tcharding
Copy link
Member

Yes please. Anything that is different in one version to another should have a separate type, errors included. I'm not totally convince that we should re-use errors at all but we already do in submitpackage IIRC and its kinda nice.

@GideonBature
Copy link
Contributor Author

Yes please. Anything that is different in one version to another should have a separate type, errors included. I'm not totally convince that we should re-use errors at all but we already do in submitpackage IIRC and its kinda nice.

Alright, noted, I am going to do that right away...

@GideonBature
Copy link
Contributor Author

What's the status of this bro? The client still has methods in that are not needed.

Yes, I want to create another PR to move the other ones out of client to where they belong in v17/mod.rs reason been that those where not part of this PR, the one that is part of this PR has been moved, already... So I will open another PR to move the other one as well.

@tcharding
Copy link
Member

tcharding commented May 7, 2025

Am I understanding you correctly: this should be in draft state until #151 goes in?

@GideonBature
Copy link
Contributor Author

#151

Yes....

@tcharding tcharding marked this pull request as draft May 8, 2025 23:32
@tcharding
Copy link
Member

If you get time mate lets get this one in and then we can cut a new release.

@GideonBature
Copy link
Contributor Author

If you get time mate lets get this one in and then we can cut a new release.

sure...

@GideonBature GideonBature force-pushed the support-29.0 branch 3 times, most recently from 8341786 to 717ab4d Compare May 13, 2025 04:39
@GideonBature GideonBature marked this pull request as ready for review May 13, 2025 04:44
@tcharding
Copy link
Member

tcharding commented May 13, 2025

No changes to v17 in a PR that adds support for v29 please.

EDIT: This should have been 'no changes to v17 types', I'd expect changes to the into_model function.

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 9a1982e to a2840af Compare May 14, 2025 09:52
@GideonBature
Copy link
Contributor Author

GideonBature commented May 14, 2025

No changes to v17 in a PR that adds support for v29 please.

Noted. I have removed the changes I made to the v17 and others. I will open a separate PR to address those.

I removed all changes made to the v17 and other versions other than v29 with this recent push. I also reduce the docs on the getdescriptoractivity struct.

@tcharding
Copy link
Member

tcharding commented May 15, 2025

We need to update verify/src/method/v29.rs because of your recent PRs.

Run diff src/method/v28.rs src/method/v29.rs to see how I worked this out.

@tcharding
Copy link
Member

There is still changes in client that don't need to be there.

@GideonBature
Copy link
Contributor Author

There is still changes in client that don't need to be there.

oh my... fixing that.

@GideonBature GideonBature force-pushed the support-29.0 branch 2 times, most recently from 3180c5c to 124e08a Compare May 15, 2025 11:39
@GideonBature
Copy link
Contributor Author

For this recent push, I removed all the unnecessary code in the client, made changes to the methods in the verify module of v29 to march the correct ones.

@GideonBature
Copy link
Contributor Author

For this recent push, I removed all the unnecessary code in the client, made changes to the methods in the verify module of v29 to march the correct ones.

"29 checks for v29" :).

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting there, keep at it man.

Comment on lines +23 to +29
let blockhashes_val = json!(blockhashes);
let scan_objects_val = json!(scan_objects);
let include_mempool_val = json!(include_mempool);

let params = vec![blockhashes_val, scan_objects_val, include_mempool_val];

self.call("getdescriptoractivity", &params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let blockhashes_val = json!(blockhashes);
let scan_objects_val = json!(scan_objects);
let include_mempool_val = json!(include_mempool);
let params = vec![blockhashes_val, scan_objects_val, include_mempool_val];
self.call("getdescriptoractivity", &params)
self.call("getdescriptoractivity", &[])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I do this, the method won't work, because all the parameters are required even if they contain no value, they are to be present as empty arrays, including the bool value. Running the test, we will always have this:

getdescriptoractivity: JsonRpc(Rpc(RpcError { code: -3, message: "JSON value of type null is not of expected type array", data: None }))

That is the reason why I had to be passing an empty array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is odd, the docs say they are optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, while working on it at first, I tried without including the parameters, and I kept getting this error while running the test. So I decided to try by passing in an empty array instead, only then did it work.

median_time,
nonce: crate::to_u32(self.nonce, "nonce")?,
bits,
// target,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this still.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why I comment it out is that if I should include it, I will need to make changes to the model type, which in turn I will have to touch the type of v17 to include this type returning None. So I intend to do that once we are done with this issue, else I will have to make changes across v17 into, as well as v28 into.

Or what do you advise I do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its expected that you'll need to update the model type. But add the new field as an option then you only have to change the v17 into_model function. I really hope you hadn't done that before when I said "no changes to v17 in this PR" - else I'll have egg on my face.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I am going to do that right away. Although I did this in the into method of v17, but seems I touched some part of 17 as well.

/// The bits.
pub bits: String,
/// The difficulty target.
pub target: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked this resolved but its not resolved.

Comment on lines 79 to 82
/// The bits
// pub bits: Option<CompactTarget>, // Only from v29 onwards
/// The difficulty target.
// pub target: Option<Target>, // Only from v29 onwards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented it out because it's going to cause errors in v17 and v28 implementation of the into method. Which I will need to resolve. Since we are not supposed to touch the other methods in this issue, I intend to work on these in a different PR.

Comment on lines 54 to 55
/// The difficulty target
// pub target: Option<Target>, // Only from v29 onwards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to uncoment this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment it, I have to make changes to the type for v17 and I think v28, which is not supposed to be a part of this PR, since this only focuses on v29. I intend to do that after working on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or instead would it be better if I exclude it completely, and bring it back in the PR I will be working to resolve this?


/// Models a script pubkey with strongly typed fields.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct ScriptPubkey {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want this. We have a bunch of useage of this type already. Are you able to do the same in this PR. I.e., convert the data out of this to the correct rust-bitcoin types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was able to convert the hex and address fields to the correct rust-bitcoin types.

@tcharding
Copy link
Member

I've a bad feeling now that I told you then wrong thing before, if so apologies for that.

@tcharding
Copy link
Member

You've put a fair bit of effort into this and I feel bad for giving the dud review. Do you want me to help you push it over the line i.e., want me to make the final changes and push them up? Totally up to you, I'm good to wait and just review also.

@GideonBature
Copy link
Contributor Author

You've put a fair bit of effort into this and I feel bad for giving the dud review. Do you want me to help you push it over the line i.e., want me to make the final changes and push them up? Totally up to you, I'm good to wait and just review also.

No problem, I am comfortable you reviewing it. I am really okay with that. :).

@GideonBature
Copy link
Contributor Author

I've a bad feeling now that I told you then wrong thing before, if so apologies for that.

No problem. Please don't feel bad, maintaining this library is not easy, as sometimes making changes to a file also affect others, so I feel sometimes missing somethings in that case is normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Bitcoin Core 29.0
2 participants